Option Explicit On

Imports System
Imports System.IO
Imports System.Web
Imports System.Web.UI
Imports System.XML
Imports System.Collections

Imports DotNetNuke
Imports DotNetNuke.Common
Imports DotNetNuke.Data
Imports DotNetNuke.Services.Exceptions

Namespace TressleWorks.Modules.ThermoChart

    Public Class ThermoChartController
        Implements Entities.Modules.IPortable


        Public Function ExportModule(ByVal ModuleID As Integer) As String Implements Entities.Modules.IPortable.ExportModule
            Dim sXML As String

            Dim objAdmin As New Entities.Modules.ModuleController
            Dim myEnumerator As IDictionaryEnumerator = objAdmin.GetModuleSettings(ModuleID).GetEnumerator()
            Dim oSortSettings As New SortedList

            While myEnumerator.MoveNext()
                oSortSettings.Add(myEnumerator.Key, myEnumerator.Value)
            End While

            sXML = "<ThermoChart>"

            myEnumerator = oSortSettings.GetEnumerator()
            While myEnumerator.MoveNext()
                sXML &= "<" & myEnumerator.Key & ">"
                sXML &= DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(myEnumerator.Value)
                sXML &= "</" & myEnumerator.Key & ">"
            End While

            sXML &= "</ThermoChart>"

            Return sXML
        End Function

        Public Sub ImportModule(ByVal ModuleID As Integer, ByVal Content As String, ByVal Version As String, ByVal UserID As Integer) Implements Entities.Modules.IPortable.ImportModule
            Dim idx As Integer
            Dim skey As String
            Dim sValue As String

            Dim objAdmin As New Entities.Modules.ModuleController
            Dim oRoot As XmlNode = GetContent(Content, "ThermoChart")
            Dim oChild As XmlNode

            If oRoot.HasChildNodes Then
                For idx = 0 To oRoot.ChildNodes.Count - 1

                    oChild = oRoot.ChildNodes(idx)
                    skey = oChild.Name
                    sValue = oChild.InnerText

                    objAdmin.UpdateModuleSetting(ModuleID, skey, sValue)

                Next idx
            End If

        End Sub


    End Class

End Namespace
